<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>全部订单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <script src="/houtai/js/vue.js"></script>
    <script type="text/javascript" src="/houtai/js/jquery-2.1.4.js"></script>

    <link rel="stylesheet" href="/houtai/layuiadmin/layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
    <style>
        .leftTitle{
            font-size: 15px;
            font-family: 微软雅黑;
            font-weight: bold;
            margin-right: 30px;
            color:#606266
        }
        .rigthContent{
            color:#606266
        }
        .lineDiv{
            margin-top: 30px;
        }
    </style>
</head>
<body>

<!--------------------------------------头部工具条------------------------------------------>
<script type="text/html" id="headbar">
    <div class="layui-btn-container"  >
    </div>
</script>

<!-------------------------------------------- 每一行工具条 --------------------------------------->
<script type="text/html" id="barDemo">
    <button type="button" class="layui-btn layui-btn-xs layui-btn-radius layui-btn-warm" lay-event="singleUpdate">
        <i class="layui-icon">&#xe642;</i> 查看
    </button>
</script>

<!---------------------------------------------条件搜索框------------------------------------------->
<div class="demoTable" style="margin-top: 10px">
    <form id="serachForm" class="layui-form" style="margin-left: 20px">
        订单编号：
        <div class="layui-inline" style="margin-right: 20px">
            <input class="layui-input" name="allorderNumber" id="myorderNumber" autocomplete="off">
        </div>
        下单人：
        <div class="layui-inline" style="width: 100px">
            <input class="layui-input" id="username" name="username" autocomplete="off">
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">下单日期</label>
            <div class="layui-input-inline" style="width: 100px">
                <input type="text" name="startDate" id="startDate" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>
            -
            <div class="layui-input-inline" style="width: 100px">
                <input type="text" name="endDate" id="endDate" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline" style="margin-left: 10px">
            <!--这个地方的不能直接使用button标签，使用button标签会重复提交数据-->
            <input type="button" class="layui-btn" data-type="reload" value="搜索">
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>

    </form>
</div>

<!-----------------------------------------表格内容--------------------------------------------->
<div id="content">
    <table class="layui-table"
           lay-data="{url:'/houtai/page/allOrder/list',page:true,limit:10,limits:[10,20,10000],toolbar:'#headbar',
                     height:'full-100',totalRow:true,loading:true,title:'用户信息表',
                     //把返回的数据result转为换layUI需要的格式，此处返回的是mybatisPlus的IPage对象，具体返回值自己设定
                     parseData: function(res){ //res 即为原始返回的数据
                     console.log(res);
                        return {
                            'code': res.code, //解析接口状态
                            'msg': res.message, //解析提示文本
                            'count': res.obj.totalSize, //解析数据长度
                            'data': res.li //解析数据列表
                          };
                       },
                //给表格设置一个ID
               id:'test'}"
           lay-filter="filter">
        <thead>
        <tr>
            <!--开起全选框-->
            <th lay-data="{checkbox:true,fixed:'left'}"></th>
            <th lay-data="{field:'allorderId',fixed:'left',hide:true}">订单ID</th>
            <!--把订单编号作为合计行标题-->
            <th lay-data="{field:'allorderNumber',minWidth:110,totalRowText:'合计',fixed:'left'}">订单编号</th>
            <!--返回对象中另一个对象的属性-->
            <th lay-data="{field:'user',
                templet:function (d) {
                    return d.user.username;
                }
            }">下单人</th>
            <th lay-data="{field:'allCreatetime',sort: true}">下单时间</th>
            <th lay-data="{field:'alltotalprice',minWidth:110,  totalRow: true,sort: true}">支付金额</th>
            <th lay-data="{field:'cupon',
                templet:function (d) {
                    if(d.cupon != null){
                        return d.cupon.cuponMoney;
                    }else{
                        return 0;
                    }

                }
            }">优惠券减免</th>
            <th lay-data="{field:'allorderOriginalprice',minWidth:110,totalRow: true,sort: true}">订单原价</th>
            <th lay-data="{field:'cupon',
                templet:function (d) {
                    if(d.cupon != null){
                        return d.cupon.cuponContent;
                    }else{
                        return '';
                    }
                }
            }">优惠券</th>
            <!--最后一列操作列，有修改或删除的权限就显示这列，否者不显示，通过Vue实现-->
            <th lay-data="{field:'opeartion', width:170,fixed: 'right', toolbar: '#barDemo'}">操作</th>
        </tr>
        </thead>
    </table>
</div>

<!-----------这里是修改弹出层的表单信息,表单的id用于表单的选择，style是在本页隐藏，只有点击编辑才会弹出---------->
<div class="layui-row" id="popUpdateUser" style="display:none;">
    <div style="width: 780px;margin-left: 10px">
        <div class="lineDiv">
            <span class="leftTitle">订单编号</span><span id="allorderNumber" class="rigthContent"></span>
        </div>
        <div class="lineDiv">
            <span class="leftTitle">下单人</span><span id="myorderUser" class="rigthContent"></span>
        </div>
        <div class="lineDiv">
            <span class="leftTitle">收货信息</span>
            <span class="rigthContent">（收货人）</span>
            <span id="acceptUser"></span>
            <span class="rigthContent">（手机号）</span>
            <span id="acceptTel"></span>
            <span class="rigthContent">（地址）</span>
            <span id="acceptAddress"></span>
        </div>
        <div class="lineDiv">
            <span class="leftTitle">订单详情</span>
        </div>
        <div class="lineDiv" style="margin-top: 10px">
            <table class="layui-table">
                <thead>
                <tr>
                    <th>子订单编号</th>
                    <th>所属商家</th>
                    <th>订单状态</th>
                    <th>物流公司</th>
                    <th>物流编号</th>
                    <th>订单小计</th>
                </tr>
                </thead>
                <tbody id="tbody">

                </tbody>
            </table>
        </div>
        <div class="lineDiv">
            <span class="leftTitle">订单总价</span><span id="myOrderTotalPrice" class="rigthContent"></span>
        </div>
        <div class="lineDiv">
            <span class="leftTitle">优惠券</span><span id="myOrderCupon" class="rigthContent"></span>
        </div>
        <div class="lineDiv">
            <span class="leftTitle">实际支付</span><span id="payPrice" class="rigthContent"></span>
        </div>

        <div style="margin:30px 700px 30px">
            <button id="closeBtn" type="button" class="layui-btn layui-btn-sm">关闭</button>
        </div>
    </div>
</div>

<script src="/houtai/layuiadmin/layui/layui.js" charset="utf-8"></script>
<script src="/houtai/layuiadmin/layui/lay/modules/util.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述js路径需要改成你本地的 -->

<!--转换时间格式、数字转字符串-->
<script type="text/javascript">
    /**
     * 将"2018-05-19T08:04:52.000+0000"这种格式的时间转化为正常格式\
     */
    function timeFormat(time) {
        var d = new Date(time);

        var year = d.getFullYear();       //年
        var month = d.getMonth() + 1;     //月
        var day = d.getDate();            //日

        var hh = d.getHours();            //时
        var mm = d.getMinutes();          //分
        var ss = d.getSeconds();           //秒

        var clock = year + "/";

        if (month < 10)
            clock += "0";

        clock += month + "/";

        if (day < 10)
            clock += "0";

        clock += day + " ";

        if (hh < 10)
            clock += "0";

        clock += hh + ":";
        if (mm < 10) clock += '0';
        clock += mm + ":";

        if (ss < 10) clock += '0';
        clock += ss;
        return (clock);
    };
</script>
<script>
    layui.use(['table','jquery','laypage','util','laydate','form'], function(){
        var table = layui.table;
        var $ = layui.jquery;
        var util = layui.util;
        var laydate = layui.laydate;
        var form = layui.form;
        //加载日期选择插件
        laydate.render({
            elem: '#startDate'
        });
        laydate.render({
            elem: '#endDate'
        });
        //刷新表单
        form.render();

        $("#closeBtn").click(function () {
            layer.closeAll();
        })

        //监听每一行工具条
        table.on('tool(filter)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            console.log(data);
            if(layEvent === 'detail'){//查看
                //do somehing
            }else if(layEvent === 'singleUpdate'){ //编辑
                console.log("当前页码");
                console.log($(".layui-laypage-em").next().html()); //当前页码值
                $.ajax({
                    url:"/houtai/page/allOrder//selectAllOrderById",
                    data:{allOrderId:data.allorderId},
                    type:"post",
                    async: false,
                    dataType:"json",
                    success:function (data) {
                        console.log("这是allOrder-------------------------")
                        console.log(data);
                        if(data.message == "success"){
                            var order = data.obj;
                            $("#allorderNumber").text(order.allorderNumber);
                            $("#myorderUser").text(order.user.username);
                            $("#acceptUser").text(order.userAddress.name);
                            $("#acceptTel").text(order.userAddress.tel);
                            $("#acceptAddress").text(order.userAddress.addr);

                            var orderDetail = order.myorders;
                            console.log("这是myorders-----------------------------")
                            console.log(orderDetail);
                            var html = "";
                            console.log(html);
                            for(var i = 0;i < orderDetail.length;i++){
                                var commentDesc = "待评价";
                                if(orderDetail[i].comment != null){
                                    commentDesc = orderDetail[i].comment.commentDesc;
                                }

                                var myorderStatus = orderDetail[i].myorderStatus;
                                var myorderStatusText = "";
                                if(myorderStatus == 0){
                                    myorderStatusText = "待付款";
                                }else if(myorderStatus == 1){
                                    myorderStatusText = "待发货";
                                }else if(myorderStatus == 2){
                                    myorderStatusText = "待收货";
                                }else if(myorderStatus == 3){
                                    myorderStatusText = "待评价";
                                }else if(myorderStatus == 4){
                                    myorderStatusText = "取消订单";
                                }else if(myorderStatus == 5){
                                    myorderStatusText = "交易完成";
                                };
                                var wuliuGongshi = orderDetail[i].wuliuGongshi;
                                var wuliuGongshiText = "";
                                if(wuliuGongshi == 'SFEXPRESS'){
                                    wuliuGongshiText = "顺丰";
                                }else if(wuliuGongshi == 'sto'){
                                    wuliuGongshiText = "申通";
                                }else if(wuliuGongshi == 'yto'){
                                    wuliuGongshiText = "圆通";
                                }else if(wuliuGongshi == 'zto'){
                                    wuliuGongshiText = "中通";
                                }else if(wuliuGongshi == 'YUNDA'){
                                    wuliuGongshiText = "韵达";
                                }else if(wuliuGongshi == 'HTKY'){
                                    wuliuGongshiText = "百世快递";
                                }else if(wuliuGongshi == 'EMS'){
                                    wuliuGongshiText = "EMS";
                                }else if(wuliuGongshi == null){
                                    wuliuGongshiText = "暂无";
                                }
                                var wuliuNumber = "";
                                if(orderDetail[i].wuliuNumber != null && orderDetail[i].wuliuNumber != ''){
                                    wuliuNumber = orderDetail[i].wuliuNumber;
                                }else{
                                    wuliuNumber = "暂无";
                                }
                                html+="<tr>"+
                                    "<td>"+orderDetail[i].myorderNumber+"</td>"+
                                    "<td>"+orderDetail[i].business.businessName+"</td>"+
                                    "<td>"+myorderStatusText+"</td>"+
                                    "<td>"+wuliuGongshiText+"</td>"+
                                    "<td>"+wuliuNumber+"</td>"+
                                    "<td>"+orderDetail[i].myorderTotalPrice+"</td>"+
                                    "</tr>";
                            }
                            console.log(html);
                            $("#tbody").html(html);
                            $("#myOrderTotalPrice").text(order.allorderOriginalprice);

                            if(order.cupon != null){
                                $("#myOrderCupon").text(order.cupon.cuponContent);
                            }else{
                                $("#myOrderCupon").text("未使用优惠券");
                            }
                            $("#payPrice").text(order.alltotalprice);

                        }
                    }
                })

                //开起弹出层
                layer.open({
                    //layer提供了5种层类型。可传入的值有：0（信息框，默认）1（页面层）2（iframe层）3（加载层）4（tips层）
                    type: 1,
                    title: "订单详情",
                    area: ['800px', '600px'],//设置弹出层尺寸

                    content: $("#popUpdateUser")//引用的弹出层的页面层的方式加载修改界面表单
                });
                // 获取表单区域所有值
                var data1 = form.val("updateForm");
            }
        });
        //监听表单提交，上述的submit()中的值为事件过滤器的值
        form.on('submit(sendProduct)', function(data){
            // console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
            // console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
            // console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
            if(data.field.wuliuNumber != null && data.field.wuliuNumber != ''){
                $.ajax({
                    url:"/houtai/page/order/sendProduct",
                    data:$("#sendProductForm").serialize(),
                    type:"post",
                    dataType:"json",
                    success:function (data) {
                        if(data.message == "success"){
                            layer.msg("提交成功");
                            layer.closeAll();
                            table.reload('test', {
                                url: '/houtai/page/order/list',
                                page: {
                                    curr: $(".layui-laypage-em").next().html() //从当前页开始重载表格
                                }
                            });
                        }else{
                            layer.msg("提交失败，请重新提交");
                        }
                    }
                })
            }
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });


        //设置搜索框查询条件
        var $ = layui.$, active = {
            reload: function(){
                var demoReload = $('#demoReload');
                var str = $("#serachForm").serialize();
                //执行重载
                table.reload('test', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    ,where: {
                        allorderNumber:$("#myorderNumber").val(),
                        username:$("#username").val(),
                        startDate:$("#startDate").val(),
                        endDate:$("#endDate").val()
                    }
                }, 'data');
            }
        };

        //监听搜索框提交按钮
        $('.demoTable .layui-btn').on('click', function(){
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

        //监听修改框提交
        form.on('submit(formDemo)', function(data){
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });
</script>

</body>
</html>